﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LogisticsBLL;

namespace WebLosgic.scripts
{
    public partial class UpdatePwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["names"] != null)
                {
                    string mingz = Session["names"].ToString();
                    string Acount = Session["Act"].ToString();
                     LabYONG.Text = mingz;
                    Txtcound.Text = Acount;
                }
                else
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('请重新登录');location.href='login.aspx'", true);
                }
               
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string oldpwd = Txtoldpwd.Text;
            string newpwd = TxtNewpwd.Text;
            string funewpwd = Txtpwdconfim.Text;
            if (oldpwd == "" || newpwd=="" || funewpwd=="")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('都不能为空')", true);
            }
            if (newpwd == oldpwd)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('新密码不能和旧密码相同')", true);
            }
            if (newpwd != funewpwd)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('两次新密码不同，请重新输入!')", true);
            }
            
            int ID = Convert.ToInt32(Session["UserIDs"]);
            string pwds = UserBLL.panduan(ID).ToString();
            if (oldpwd != pwds)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('旧密码有错误，请重新输入!')", true);
            }
            int rseult = UserBLL.uppwd(TxtNewpwd.Text,ID);

            string name = Session["names"].ToString();
            string Behavor = "" + name + ": 修改密码";
            int TypeId = 4;
            int UserID = Convert.ToInt32(Session["UserIDs"]);
            string Parameters = @"" + Txtoldpwd.Text + "," + TxtNewpwd.Text + "," + Txtcound.Text ;
            string ProcName = "p_updpwd";
            HttpRequest request = HttpContext.Current.Request;
            string IP = "192.168.0.1";
            int IsExcePion = 0;
            if (rseult > 0)
            {
                IsExcePion = 0;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
                if (a > 0)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('修改成功');location.href='index.aspx'", true);
                }
                
            }
            else
            {
                IsExcePion = 1;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
                if (a > 0)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('修改失败')", true);
                }
                
            }
        }
    }
}